package servlet;

import dao.Bus_userDao;
import dao.Order_contentDao;
import dao.OrdersDao;
import dao.impl.Bus_userDaoImpl;
import dao.impl.Order_contentDaoImpl;
import dao.impl.OrdersDaoImpl;
import pojo.Bus_user;
import pojo.Order_content;
import pojo.Orders;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/bus_OrderViewServlet.do")
public class bus_OrderViewServlet extends HttpServlet {
    private static Bus_userDao bus_userDao=new Bus_userDaoImpl();
    private static Order_contentDao order_contentDao=new Order_contentDaoImpl();
    private static OrdersDao ordersDao=new OrdersDaoImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        List<Bus_user> bus_userBybus_username = bus_userDao.findBus_userBybus_username(username);
        Bus_user bus_user=bus_userBybus_username.get(0);
        Integer bus_no = bus_user.getBus_no();

        List<Order_content> order_contentList = order_contentDao.findAllOrder_contentBybus_no(bus_no);
        req.setAttribute("order_contentList",order_contentList);

        List<Orders> ordersList = ordersDao.queryIncompleteOrder();
        req.setAttribute("ordersList",ordersList);
        getServletContext().setAttribute("ordersList",ordersList);

        req.getRequestDispatcher("bus_View.jsp").forward(req,resp);


    }
}
